CONTENTS | INDEX | PREV | NEXT
strtok

   NAME
    strtok  - Break up a string into arguments

   SYNOPSIS
    char *arg = strtok(s, toks)
    char *s;
    const char *toks;

   FUNCTION
    strtok() breaks up a string into arguments.  It determines the break
    point from the 'toks' string which contains a set of white space
    characters (usually " t" to mean space and tab).

    The first call to strtok() should specify the string s and toks.
    Initial white space is skipped and the string is then scanned
    until the end of the first argument is found.  The string is
    then MODIFIED... a nul is placed at the end of the first argument
    and a pointer to the beginning of the first argument is returned.

    Further calls to strtok() should pass a NULL for the string s,
    which tells strtok() to continue scanning the original string (whos
    pointer was stored in a static char * within strtok).

    strtok() returns arguments until the string is exhausted, in which
    case is returns NULL.  The initial call to strtok() can return NULL
    if the passed string s contains nothing but whitespace (as specified
    by toks).

    You can change the toks string at any time (i.e. pass a different
    toks string to strtok).

   WARNING
    strtok modifies the source string and returns pointers into it.

   EXAMPLE
    #include <stdio.h>
    #include <string.h>

    main()
    {
        char buf[32];
        char *arg;
        const char *ws = " t";

        /*
         *  'This' 'is' 'a' 'test!'
         */

        strcpy(buf, "  This  is t t a test!");
        for (arg = strtok(buf, ws); arg; arg = strtok(NULL, ws)) {
        printf("arg = '%s'n", arg);
        }
        return(0);
    }

   INPUTS
    char *s;    pointer to string to parse
    char *toks; pointer to string containing whitespace characters
            (argument delimiters)

   RESULTS
    char *arg;  pointer into s to next argument that is nul
            terminated (s is modified).

   SEE ALSO
    strspn, strcspn